﻿package  com.efg.framework
{
	// Import necessary classes from the flash library
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextFormatAlign;
	
	
	/**
	 * BasicScreen类是用来在屏幕上显示状态画面的类.
	 * @author Jeff Fulton
	 */
	public class BasicScreen extends Sprite {
		
		
		private var displayText:TextField = new TextField();
		private var backgroundBitmapData:BitmapData;
		private var backgroundBitmap:Bitmap;
		private var okButton:SimpleBlitButton;
		
		//ID is passed into the constructor. When the OK button is clicked, a custom event sends this id back to Main
		private var id:int;
		
		//Constructor accepts our two passed in vars and then calls init
		public function BasicScreen(id:int,width:Number, height:Number, isTransparent:Boolean, color:uint) {
			this.id = id;
			backgroundBitmapData = new BitmapData(width, height, isTransparent, color);
			backgroundBitmap = new Bitmap(backgroundBitmapData);
			addChild(backgroundBitmap);
		}
		
		/**
		* @param	text 这个参数会改变TextField的.text属性。
		* @param	width 宽度的单位是像素。
		* @param	location 用一个Point类实例来定义文本域左上角注册点的x坐标和y坐标。
		* @param	textFormat 一个TextFormat实例用来设置TextFeild的文本格式。
		*/
		public function createDisplayText(text:String, width:Number, location:Point, textFormat:TextFormat):void {
			displayText.y = location.y;
			displayText.x = location.x;
			displayText.width = width;
			displayText.defaultTextFormat=textFormat;
			displayText.text = text;
			addChild(displayText);
		}
		
        /**
        * @param	text 按钮上方的文字
        * @param	location 用一个Point类实例来设置按钮注册点的坐标。
        * @param	width 按钮的宽度。
        * @param	height 按钮的高度。
        * @param	textFormat 按钮文字的字体格式。
        * @param	offColor 按钮在OFF状态下的背景色。
        * @param	overColor 按钮在over状态下的背景色。
        * @param	positionOffset 让按钮的文字在两种状态切换的时浮动效果的距离。
        */
		public function createOkButton(text:String,location:Point, width:Number, height:Number, textFormat:TextFormat, offColor:uint=0x000000, overColor:uint=0xff0000, positionOffset:Number=0):void {
			okButton = new SimpleBlitButton(location.x, location.y, width, height, text, 0xffffff, 0xff0000, textFormat, positionOffset);
			addChild(okButton);
			okButton.addEventListener(MouseEvent.MOUSE_OVER, okButtonOverListener, false, 0, true);
			okButton.addEventListener(MouseEvent.MOUSE_OUT, okButtonOffListener, false, 0, true);
			okButton.addEventListener(MouseEvent.CLICK, okButtonClickListener, false, 0, true);
		}
	
		
		public function setDisplayText(text:String):void {
			displayText.text = text;
		}
		
		//Listener functions 
		//okButtonClicked fires off a custom event and sends the "id" to the listener.
		private function okButtonClickListener(e:MouseEvent):void {
			dispatchEvent(new CustomEventButtonId(CustomEventButtonId.BUTTON_ID,id));
		}
		
		private function okButtonOverListener(e:MouseEvent):void {
			okButton.changeBackGroundColor(SimpleBlitButton.OVER);
		}
		
		private function okButtonOffListener(e:MouseEvent):void {
			okButton.changeBackGroundColor(SimpleBlitButton.OFF);
		}
		
	}
	
}